package com.lekang.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.domain.RefundRecord;
import com.lekang.service.IRefundRecordService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 退款记录Controller
 * 
 * @author ruitong
 * @date 2025-10-14
 */
@RestController
@RequestMapping("/refund/refund")
public class RefundRecordController extends BaseController
{
    @Autowired
    private IRefundRecordService refundRecordService;

    /**
     * 查询退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:list')")
    @GetMapping("/list")
    public TableDataInfo list(RefundRecord refundRecord)
    {
        startPage();
        List<RefundRecord> list = refundRecordService.selectRefundRecordList(refundRecord);
        return getDataTable(list);
    }

    /**
     * 导出退款记录列表
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:export')")
    @Log(title = "退款记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RefundRecord refundRecord)
    {
        List<RefundRecord> list = refundRecordService.selectRefundRecordList(refundRecord);
        ExcelUtil<RefundRecord> util = new ExcelUtil<RefundRecord>(RefundRecord.class);
        util.exportExcel(response, list, "退款记录数据");
    }

    /**
     * 获取退款记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(refundRecordService.selectRefundRecordById(id));
    }

    @PreAuthorize("@ss.hasPermi('refund:refund:query')")
    @GetMapping("/getInfoByOrderNo")
    public AjaxResult getInfoByOrderNo(String orderNo)
    {
        return success(refundRecordService.selectRefundRecordByOrderNO(orderNo));
    }

    /**
     * 新增退款记录
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:add')")
    @Log(title = "退款记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RefundRecord refundRecord)
    {
        return toAjax(refundRecordService.insertRefundRecord(refundRecord));
    }

    /**
     * 修改退款记录
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:edit')")
    @Log(title = "退款记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RefundRecord refundRecord)
    {
        return toAjax(refundRecordService.updateRefundRecord(refundRecord));
    }

    /**
     * 删除退款记录
     */
    @PreAuthorize("@ss.hasPermi('refund:refund:remove')")
    @Log(title = "退款记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(refundRecordService.deleteRefundRecordByIds(ids));
    }
}
